'use strict';
const { Service } = require('egg');
const p = require('path');
const fs = require('fs-extra');

class FileService extends Service {
  async savePic(file, params) {
    const { config } = this;
    let { filename } = params;
    console.log(filename)
    let filepath = params.type == 'tv' ? p.join(config.space.tv_img_space, filename) : p.join(config.space.movie_img_space, filename);
    fs.copyFileSync(file.filepath, filepath);
    fs.unlinkSync(file.filepath);
  }
}

module.exports = FileService;
